﻿@model IEnumerable<MenuItem>

@{
	var routeControllerName = Html.ControllerName();
	var routeActionName = Html.ActionName();

	List<MenuItem> oneLevelMenuItems = Model.ToList();
	foreach(var m in Model)
	{
		if(m.MenuItems != null && m.MenuItems.Count > 0)
		{
			oneLevelMenuItems.AddRange(m.MenuItems);
		}
	}
     
	var menuText = routeControllerName.ToLower() == "home" ? 
        null : 
        (from m in oneLevelMenuItems 
         where CompareUtility.IsStringsEqual(Html.GetControllerName(m.NavigateUrl), routeControllerName) && 
         !CompareUtility.IsStringsEqual(Html.GetActionName(m.NavigateUrl), routeActionName) 
         select m.Text).FirstOrDefault();

    Dictionary<string, string> customMenu = ViewBag.CustomMenu;
}
 
<ul class="breadcrumb">
	<li> 
		<i class="icon-home"></i>
		<strong>@Html.ActionLink("หน้าหลัก", "Index", "Home" )</strong>
		<span class="divider">
			<i class="icon-angle-right"></i>
		</span>
	</li>
					
    @if(customMenu == null)
    {
        if (!string.IsNullOrWhiteSpace(menuText))
         {
             <li>
                 @Html.ActionLink(menuText, "Index", routeControllerName)
                 <span class="divider">
                     <i class="icon-angle-right"></i>
                 </span>
             </li>
         }
        <li class="active">@Html.Raw(ViewBag.TitleNav as string ?? ViewBag.Title as string)</li>
    } else
    {
        foreach (var cm in customMenu)
        {  
            <li>
                <a href="@cm.Value">@cm.Key</a>
                <span class="divider">
                    <i class="icon-angle-right"></i>
                </span>
            </li> 
        }
        
        <li class="active">@Html.Raw(ViewBag.TitleNav as string ?? ViewBag.Title as string)</li>
    }
</ul><!--.breadcrumb-->